/**
 * ModelStore class - Singleton that stores the processed application model.
 */
export class ModelStore {
  private static _instance: ModelStore;
  private _businessObjects: any[] = [];
  private _views: any[] = [];
  private _navigation: any = null;

  /**
   * Get the singleton instance of the ModelStore
   */
  public static getInstance(): ModelStore {
    if (!ModelStore._instance) {
      ModelStore._instance = new ModelStore();
    }
    return ModelStore._instance;
  }

  private constructor() {
    // Private constructor to enforce singleton pattern
  }

  /**
   * Set the business object definitions
   * @param businessObjects Business object definitions
   */
  public setBusinessObjects(businessObjects: any[]): void {
    this._businessObjects = [...businessObjects];
  }

  /**
   * Get all business object definitions
   */
  public get businessObjects(): any[] {
    return [...this._businessObjects];
  }

  /**
   * Get a business object definition by name
   * @param name The name of the business object
   */
  public getBusinessObjectByName(name: string): any | null {
    return this._businessObjects.find(bo => bo.name === name) || null;
  }

  /**
   * Set the view definitions
   * @param views View definitions
   */
  public setViews(views: any[]): void {
    this._views = [...views];
  }

  /**
   * Get all view definitions
   */
  public get views(): any[] {
    return [...this._views];
  }

  /**
   * Get a view definition by name
   * @param name The name of the view
   */
  public getViewByName(name: string): any | null {
    return this._views.find(view => view.name === name) || null;
  }

  /**
   * Set the navigation definition
   * @param navigation Navigation definition
   */
  public setNavigation(navigation: any): void {
    this._navigation = navigation;
  }

  /**
   * Get the navigation definition
   */
  public get navigation(): any {
    return this._navigation;
  }
}
